//Cracking the coding interview (5th), 1_3
// Given two strings, write a method to decide if one is a permutation of the other
//8:20PM-8:28PM(bug free)

#include<iostream>
#include<string>
#include<cstring>
using namespace std;

bool permutation(string &str1, string &str2) 
{
	int count[256];
	memset(count, 0, 256*sizeof(int));

	for(int i=0; i<str1.size(); i++) 
		count[str1[i]]++;

	for(int i=0; i<str2.size(); i++) {
		if(!count[str2[i]]) return false;
		count[str2[i]]--;
	}

	return true;
}

int main(int argc, char *argv[]) 
{
	string s1("This is PV");
	string s2("This is Pv");
        string s3("is This PV");
	bool b1=permutation(s1, s2);
        bool b2=permutation(s1, s3);

        if(!b1 && b2)
          cout<<"Pass test"<<endl;
        else
          cout<<"Fail test"<<endl;

	return 0;
}
